﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class JumpCheck : MonoBehaviour
{
    public GameObject parentCheck ;
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        
    }
    private void OnTriggerEnter2D(Collider2D collision)
    {
        //判断在磁铁使用过程中 阴影角色为没踩到地面，而角色踩到地面或者碰撞到墙壁时
        if (parentCheck.GetComponent<Player>().parent != null && !parentCheck.GetComponent<TimeBack>().isActioning)
        {
            if (collision.gameObject.CompareTag("Ground"))
            {
                print("本体"+parentCheck.GetComponent<CharacterController2D>().isGrounded);
                print("阴影"+parentCheck.GetComponent<Player>().parent.GetComponent<CharacterController2D>().isGrounded);
                if (!parentCheck.GetComponent<Player>().parent.GetComponent<CharacterController2D>().isGrounded)
                {
                    print("脱钩");
                    parentCheck.GetComponent<Rigidbody2D>().bodyType = RigidbodyType2D.Dynamic;
                    parentCheck.GetComponent<Player>().parent.GetComponentInChildren<Magnet>().RemoveChildren();                 
                }
            }
        }
    }
}
